import javax.swing.table.AbstractTableModel;


public class DownloadTableModel extends AbstractTableModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String columnNames[] = { "Nazwa pliku", "Rozmiar", "Progress" };
	
	private Object data [][];
	private int count;
	
	public DownloadTableModel() {
		count = 0;
		data = new Object[count][3];
		
	}

	@Override
	public int getColumnCount() {
		return columnNames.length;
	}

	@Override
	public int getRowCount() {
		return data.length;
	}
	
	public String getColumnName(int col) {
        return columnNames[col];
    }

	@Override
    public Object getValueAt(int row, int col) {
        return data[row][col];
    }
	
	public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }
	
	public void setData(Object[][] d, int c){
		data = d;
		count = c;
	}
	
	public void addFile(String filename, int size, int progress) {
		int c = count+1;
		Object newData[][] = new Object[c][3];
		for(int i=0; i<count; i++) {
			//if(data[i][0] == null || (((String)data[i][0]).compareTo("Poki co") == 0)) {
			newData[i][0] = data[i][0];
			newData[i][1] = data[i][1];
			newData[i][2] = data[i][2];
			//	break;
			//} 
		}
		newData[count][0] = filename;
		newData[count][1] = ""+size;
		newData[count][2] = progress;
		setData(newData, c);
		
	}
	
	public void updateFile(String filename, int size, int progress) {
		for(int i=0; i<count; i++) {
			if(data[i][0] != null)
			if((((String)data[i][0]).compareTo(filename) == 0)) {
				data[i][2] = progress;
				break;
			}
		}
		setData(data, count);
		
	}
}
